home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / vigilant.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  10KB  |  402 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7.   TODO:
  8.  
  9.   - Get a dump of the PAL16L8 (IC38 - 4M).  This controls transparency.
  10.     It takes as input 4 bits of sprite color, and 6 bits of background tile
  11.     color.  It outputs a sprite enable line, a background enable line, and
  12.     a background select (which layer of background to draw).
  13.   - Add cocktail flipping.
  14.  
  15. ***************************************************************************/
  16.  
  17. #include "driver.h"
  18. #include "vidhrdw/generic.h"
  19.  
  20.  
  21. static struct rectangle topvisiblearea =
  22. {
  23.     16*8, 48*8-1,
  24.     0*8, 6*8-1
  25. };
  26. static struct rectangle bottomvisiblearea =
  27. {
  28.     16*8, 48*8-1,
  29.     6*8, 32*8-1
  30. };
  31.  
  32. unsigned char *vigilant_paletteram;
  33. unsigned char *vigilant_sprite_paletteram;
  34.  
  35. static int horiz_scroll_low=0;
  36. static int horiz_scroll_high=0;
  37. static int rear_horiz_scroll_low=0;
  38. static int rear_horiz_scroll_high=0;
  39. static int rear_color=0;
  40. static int rear_disable=1;
  41.  
  42. static int rear_refresh=1;
  43.  
  44. static struct osd_bitmap *bg_bitmap;
  45.  
  46.  
  47. int vigilant_vh_start(void)
  48. {
  49.     generic_vh_start();
  50.  
  51.     if ((bg_bitmap = osd_create_bitmap(512*3,256)) == 0)
  52.     {
  53.         generic_vh_stop();
  54.         return 1;
  55.     }
  56.  
  57.     return 0;
  58. }
  59.  
  60. void vigilant_vh_stop(void)
  61. {
  62.     osd_free_bitmap(bg_bitmap);
  63.     generic_vh_stop();
  64. }
  65.  
  66.  
  67.  
  68. /***************************************************************************
  69.  update_background
  70.  
  71.  There are three background ROMs, each one contains a 512x256 picture.
  72.  Redraw them if the palette changes.
  73.  **************************************************************************/
  74. static void update_background( void )
  75. {
  76.     int row,col,page;
  77.     int charcode;
  78.  
  79.  
  80.     charcode=0;
  81.  
  82.     /* There are only three background ROMs */
  83.     for (page=0; page<3; page++)
  84.     {
  85.         for( row=0; row<256; row++ )
  86.         {
  87.             for( col=0; col<512; col+=32 )
  88.             {
  89.                 drawgfx(bg_bitmap,
  90.                         Machine->gfx[2],
  91.                         charcode,
  92.                         row < 128 ? 0 : 1,
  93.                         0,0,
  94.                         512*page + col,row,
  95.                         0,TRANSPARENCY_NONE,0);
  96.                 charcode++;
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102. /***************************************************************************
  103.  vigilant_paletteram_w
  104.  
  105.  There are two palette chips, each one is labelled "KNA91H014".  One is
  106.  used for the sprites, one is used for the two background layers.
  107.  
  108.  The chip has three enables (!CS, !E0, !E1), R/W pins, A0-A7 as input,
  109.  'L' and 'H' inputs, and D0-D4 as input.  'L' and 'H' are used to bank
  110.  into Red, Green, and Blue memory.  There are only 5 bits of memory for
  111.  each byte, and a total of 256*3 bytes memory per chip.
  112.  
  113.  There are additionally two sets of D0-D7 inputs per chip labelled 'A'
  114.  and 'B'.  There is also an 'S' pin to select between the two input sets.
  115.  These are used to index a color triplet of RGB.  The triplet is read
  116.  from RAM, and output to R0-R4, G0-G4, and B0-B4.
  117.  **************************************************************************/
  118. WRITE_HANDLER( vigilant_paletteram_w )
  119. {
  120.     int bank,r,g,b;
  121.  
  122.  
  123.     paletteram[offset] = data;
  124.  
  125.     bank = offset & 0x400;
  126.     offset &= 0xff;
  127.  
  128.     r = (paletteram[bank + offset + 0x000] << 3) & 0xFF;
  129.     g = (paletteram[bank + offset + 0x100] << 3) & 0xFF;
  130.     b = (paletteram[bank + offset + 0x200] << 3) & 0xFF;
  131.  
  132.     palette_change_color((bank >> 2) + offset,r,g,b);
  133. }
  134.  
  135.  
  136.  
  137. /***************************************************************************
  138.  vigilant_horiz_scroll_w
  139.  
  140.  horiz_scroll_low  = HSPL, an 8-bit register
  141.  horiz_scroll_high = HSPH, a 1-bit register
  142.  **************************************************************************/
  143. WRITE_HANDLER( vigilant_horiz_scroll_w )
  144. {
  145.     if (offset==0)
  146.         horiz_scroll_low = data;
  147.     else
  148.         horiz_scroll_high = (data & 0x01) * 256;
  149. }
  150.  
  151. /***************************************************************************
  152.  vigilant_rear_horiz_scroll_w
  153.  
  154.  rear_horiz_scroll_low  = RHSPL, an 8-bit register
  155.  rear_horiz_scroll_high = RHSPH, an 8-bit register but only 3 bits are saved
  156. ***************************************************************************/
  157. WRITE_HANDLER( vigilant_rear_horiz_scroll_w )
  158. {
  159.     if (offset==0)
  160.         rear_horiz_scroll_low = data;
  161.     else
  162.         rear_horiz_scroll_high = (data & 0x07) * 256;
  163. }
  164.  
  165. /***************************************************************************
  166.  vigilant_rear_color_w
  167.  
  168.  This is an 8-bit register labelled RCOD.
  169.  D6 is hooked to !ROME (rear_disable)
  170.  D3 = RCC2 (rear color bit 2)
  171.  D2 = RCC1 (rear color bit 1)
  172.  D0 = RCC0 (rear color bit 0)
  173.  
  174.  I know it looks odd, but D1, D4, D5, and D7 are empty.
  175.  
  176.  What makes this extremely odd is that RCC is supposed to hook up to the
  177.  palette.  However, the top four bits of the palette inputs are labelled:
  178.  "RCC3", "RCC2", "V256E", "RCC0".  Methinks there's a typo.
  179.  **************************************************************************/
  180. WRITE_HANDLER( vigilant_rear_color_w )
  181. {
  182.     rear_disable = data & 0x40;
  183.     rear_color = (data & 0x0d);
  184. }
  185.  
  186. /***************************************************************************
  187.  draw_foreground
  188.  
  189.  ???
  190.  **************************************************************************/
  191. static void draw_foreground( struct osd_bitmap *bitmap, int priority, int opaque )
  192. {
  193.     int offs;
  194.     int scroll = -(horiz_scroll_low + horiz_scroll_high);
  195.  
  196.  
  197.     for (offs = 0; offs<videoram_size; offs+=2 )
  198.     {
  199.         int sy = 8 * ((offs/2) / 64);
  200.         int sx = 8 * ((offs/2) % 64);
  201.         int attributes = videoram[offs+1];
  202.         int color = attributes & 0x0F;
  203.         int tile_number = videoram[offs] | ((attributes & 0xF0) << 4);
  204.  
  205.         if (priority)     /* foreground */
  206.         {
  207.             if ((color & 0x0c) == 0x0c)    /* mask sprites */
  208.             {
  209.                 if (sy >= 48)
  210.                 {
  211.                     sx = (sx + scroll) & 0x1ff;
  212.  
  213.                     if (sx > 16*8-8 && sx < 48*8)
  214.                     {
  215.                         drawgfx(bitmap,Machine->gfx[0],
  216.                                 tile_number,
  217.                                 color,
  218.                                 0,0,
  219.                                 sx,sy,
  220.                                 &bottomvisiblearea,TRANSPARENCY_PENS,0x00ff);
  221.                     }
  222.                 }
  223.             }
  224.         }
  225.         else     /* background */
  226.         {
  227.             if (dirtybuffer[offs] || dirtybuffer[offs+1])
  228.             {
  229.                 dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
  230.  
  231.                 drawgfx(tmpbitmap,Machine->gfx[0],
  232.                         tile_number,
  233.                         color,
  234.                         0,0,
  235.                         sx,sy,
  236.                         0,TRANSPARENCY_NONE,0);
  237.             }
  238.         }
  239.     }
  240.  
  241.     if (priority == 0)
  242.     {
  243.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
  244.         copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&bottomvisiblearea,
  245.                 opaque ? TRANSPARENCY_NONE : TRANSPARENCY_PEN,palette_transparent_pen);
  246.     }
  247. }
  248.  
  249.  
  250.  
  251. /***************************************************************************
  252.  draw_background
  253.  
  254.  ???
  255.  **************************************************************************/
  256. static void draw_background( struct osd_bitmap *bitmap )
  257. {
  258.     int scrollx = 0x17a + 16*8 - (rear_horiz_scroll_low + rear_horiz_scroll_high);
  259.  
  260.  
  261.     if (rear_refresh)
  262.     {
  263.         update_background( );
  264.         rear_refresh=0;
  265.     }
  266.  
  267.     copyscrollbitmap(bitmap,bg_bitmap,1,&scrollx,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
  268. }
  269.  
  270. /***************************************************************************
  271.  
  272.   Draw the game screen in the given osd_bitmap.
  273.   Do NOT call osd_update_display() from this function, it will be called by
  274.   the main emulation engine.
  275.  
  276. ***************************************************************************/
  277.  
  278. static void draw_sprites(struct osd_bitmap *bitmap,const struct rectangle *clip)
  279. {
  280.     int offs;
  281.  
  282.     for (offs = 0;offs < spriteram_size;offs += 8)
  283.     {
  284.         int code,color,sx,sy,flipx,flipy,h,y;
  285.  
  286.         code = spriteram[offs+4] | ((spriteram[offs+5] & 0x0f) << 8);
  287.         color = spriteram[offs+0] & 0x0f;
  288.         sx = (spriteram[offs+6] | ((spriteram[offs+7] & 0x01) << 8));
  289.         sy = 256+128 - (spriteram[offs+2] | ((spriteram[offs+3] & 0x01) << 8));
  290.         flipx = spriteram[offs+5] & 0x40;
  291.         flipy = spriteram[offs+5] & 0x80;
  292.         h = 1 << ((spriteram[offs+5] & 0x30) >> 4);
  293.         sy -= 16 * h;
  294.  
  295.         for (y = 0;y < h;y++)
  296.         {
  297.             int c = code;
  298.  
  299.             if (flipy) c += h-1-y;
  300.             else c += y;
  301.  
  302.             drawgfx(bitmap,Machine->gfx[1],
  303.                     c,
  304.                     color,
  305.                     flipx,flipy,
  306.                     sx,sy + 16*y,
  307.                     clip,TRANSPARENCY_PEN,0);
  308.         }
  309.     }
  310. }
  311.  
  312. void vigilant_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  313. {
  314.     int i;
  315.  
  316.  
  317.     if (rear_disable)     /* opaque foreground */
  318.     {
  319.         for (i = 0;i < 8;i++)
  320.             palette_used_colors[256 + 16*i] = PALETTE_COLOR_USED;
  321.     }
  322.     else
  323.     {
  324.         for (i = 0;i < 8;i++)
  325.             palette_used_colors[256 + 16*i] = PALETTE_COLOR_TRANSPARENT;
  326.     }
  327.  
  328.  
  329.     /* copy the background palette */
  330.     for (i = 0;i < 16;i++)
  331.     {
  332.         int r,g,b;
  333.  
  334.  
  335.         r = (paletteram[0x400 + 16 * rear_color + i] << 3) & 0xFF;
  336.         g = (paletteram[0x500 + 16 * rear_color + i] << 3) & 0xFF;
  337.         b = (paletteram[0x600 + 16 * rear_color + i] << 3) & 0xFF;
  338.  
  339.         palette_change_color(512 + i,r,g,b);
  340.  
  341.         r = (paletteram[0x400 + 16 * rear_color + 32 + i] << 3) & 0xFF;
  342.         g = (paletteram[0x500 + 16 * rear_color + 32 + i] << 3) & 0xFF;
  343.         b = (paletteram[0x600 + 16 * rear_color + 32 + i] << 3) & 0xFF;
  344.  
  345.         palette_change_color(512 + 16 + i,r,g,b);
  346.     }
  347.  
  348.     if (palette_recalc())
  349.     {
  350.         memset(dirtybuffer,1,videoram_size);
  351.         rear_refresh = 1;
  352.     }
  353.  
  354.     if (rear_disable)     /* opaque foreground */
  355.     {
  356.         draw_foreground(bitmap,0,1);
  357.         draw_sprites(bitmap,&bottomvisiblearea);
  358.         draw_foreground(bitmap,1,1);
  359.     }
  360.     else
  361.     {
  362.         draw_background(bitmap);
  363.         draw_foreground(bitmap,0,0);
  364.         draw_sprites(bitmap,&bottomvisiblearea);
  365.         draw_foreground(bitmap,1,0); // priority tiles
  366.     }
  367. }
  368.  
  369. void kikcubic_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  370. {
  371.     int offs;
  372.  
  373.  
  374.     if (palette_recalc())
  375.         memset(dirtybuffer,1,videoram_size);
  376.  
  377.     for (offs = 0; offs<videoram_size; offs+=2 )
  378.     {
  379.         int sy = 8 * ((offs/2) / 64);
  380.         int sx = 8 * ((offs/2) % 64);
  381.         int attributes = videoram[offs+1];
  382.         int color = (attributes & 0xF0) >> 4;
  383.         int tile_number = videoram[offs] | ((attributes & 0x0F) << 8);
  384.  
  385.         if (dirtybuffer[offs] || dirtybuffer[offs+1])
  386.         {
  387.             dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
  388.  
  389.             drawgfx(tmpbitmap,Machine->gfx[0],
  390.                     tile_number,
  391.                     color,
  392.                     0,0,
  393.                     sx,sy,
  394.                     0,TRANSPARENCY_NONE,0);
  395.         }
  396.     }
  397.  
  398.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  399.  
  400.     draw_sprites(bitmap,&Machine->drv->visible_area);
  401. }
  402.